const express = require("express");
const formatResponse = require("../utils/responseFormat");
const project = require("../service/projectService");

const projectRouter = express.Router();

//添加项目
projectRouter.post("/", async (req, res, next) => {
  const info = req.body;
  const data = await project.addPorject(info);
  res.send(formatResponse(0, "", data));
});

//修改项目
projectRouter.put("/:id", async (req, res, next) => {
  const id = req.params.id;
  const data = await project.updateProject(id, req.body);
  res.send(formatResponse(0, "", data));
});

//删除项目
projectRouter.delete("/:id", async (req, res, next) => {
  const id = req.params.id;
  const data = await project.deleteProject(id);
  res.send(formatResponse(0, "", data));
});

//获取项目
projectRouter.get("/", async (req, res, next) => {
  const data = await project.getProject();
  res.send(formatResponse(0, "", data));
});

module.exports = projectRouter;
